#include <bits/stdc++.h>
using namespace std;
const int maxr = 200+10, maxc = 50*4+10;
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};
int m[maxr][maxc];
int cnt, R, C;

inline bool in(int r, int c){
    return r>=0 && r<R && c>=0 && c<C;
}

void find1(int r, int c){
    m[r][c] = cnt;
    for (int i = 0; i < 4; ++i) {
        int tr = r+dr[i], tc = c+dc[i];
        if(in(tr, tc) && m[tr][tc] == 1) find1(tr, tc);
    }
}

void fill1(int r, int c){
    m[r][c] = 1;
    for (int i = 0; i < 4; ++i) {
        int tr = r+dr[i], tc = c+dc[i];
        if(in(tr, tc) && (m[tr][tc] == 0)) fill1(tr, tc);
    }
}

void find0(int r, int c, int id){
    m[r][c] = id;
    for (int i = 0; i < 4; ++i) {
        int tr = r+dr[i], tc = c+dc[i];
        if(in(tr, tc) && m[tr][tc] == 0) find0(tr, tc, id);
    }
}

void display(){
    for (int r = 0; r < R; ++r) {
        for (int c = 0; c < C; ++c) {
            cout << m[r][c];
        }
        cout << "\n";
    }
    cout << "\n";
}
char code[] = {'W','A', 'K', 'J', 'S', 'D'};
int main() {
    //ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int N, T= 0;
    while(cin >> R >> N && R && N){
        memset(m, 0, sizeof(m));
        C = 8*N+2;
        R += 2;
        cin.get();
         ++T;
        for (int r = 1; r < R-1; ++r) {
            string s; getline(cin, s);
            int c = 1;
            for (int j = 0; j < s.size(); ++j) {
                char ch = s[j];
                int t = isdigit(ch)? ch-'0' : ch-'a'+10;
                stack<int> stack;
                while(t) {stack.push(t%2); t/=2;}
                while(stack.size() < 4) stack.push(0);
                while(!stack.empty()) {m[r][c++] = stack.top(); stack.pop();}
            }
        }

        //display();
        cnt = 1;
        multiset<char> ans;
        for (int r = 0; r < R; ++r) {
            for (int c = 0; c < C; ++c) {
                if(m[r][c] == 1) {++cnt; find1(r, c);}
            }
        }

        //display();

        if(m[0][0] == 0) fill1(0, 0);

        //display();

        vector<int> quan(cnt+1, 0);
        for (int r = 0; r < R; ++r) {
            for (int c = 0; c < C; ++c) {
                if(m[r][c] == 0) {
                    int id = 0;
                    for (int i = 0; i < 4; ++i){
                        int tr = r+dr[i], tc = c+dc[i];
                        if(in(tr, tc) && m[tr][tc] != 0) id = m[tr][tc];
                    }
                    ++quan[id];
                    find0(r, c, id);
                }
            }
        }

        //display();

        for (int i = 2; i <= cnt; ++i) {
            int t = quan[i];
            char ch = code[t];
            ans.insert(ch);
        }

        cout << "Case " << T << ": ";
        for (auto i:ans) cout << i;
        cout << '\n';

    }
    return 0;
}